package com.yyc.system.controller;
import com.yyc.core.Result;
import com.yyc.core.ResultGenerator;
import com.yyc.system.model.TQuestion;
import com.yyc.system.service.ITQuestionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
* Created by yyc on 2019/01/01.
*/
@RestController
@RequestMapping("/t/question")
public class TQuestionController {
    @Autowired
    private ITQuestionService tQuestionService;

    @RequestMapping("/add")
    public Result add(@RequestBody TQuestion tQuestion) {
        tQuestionService.save(tQuestion);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        tQuestionService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody TQuestion tQuestion) {
        tQuestionService.update(tQuestion);
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        TQuestion tQuestion = tQuestionService.findById(id);
        return ResultGenerator.genSuccessResult(tQuestion);
    }

    @RequestMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<TQuestion> list = tQuestionService.findAll();
        PageInfo<TQuestion> pageInfo = new PageInfo<TQuestion>(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
